package com.example.demo.zookeeper.config;

import org.apache.zookeeper.*;
import org.apache.zookeeper.data.Stat;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

/**
 * @author liweizhi
 * @date 2020/6/21
 */
public class TestConfig {
    ZooKeeper zk;

    @Before
    public void connect() {
        zk = ZkUtil.zk;
    }

    @After
    public void close() {
        try {
            zk.close();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void getConf() {
        MyConf conf = new MyConf();
        WatcherCallback watcherCallback = new WatcherCallback(zk, conf);
        watcherCallback.aWait();
        // 模拟业务端使用配置
        while (true) {
            System.out.println(conf.getConf());
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

}
